package com.naiterui.ehp.bs.ds.modules.goods.controller.inner;

import com.naiterui.ehp.bp.security.annotation.AnonymousGetMapping;
import com.naiterui.ehp.bp.security.annotation.AnonymousPostMapping;
import com.naiterui.ehp.bp.security.annotation.AnonymousPutMapping;
import com.naiterui.ehp.bp.support.exception.BusinessException;
import com.naiterui.ehp.bp.support.exception.PublicService;
import com.naiterui.ehp.bp.support.exception.ResponseVO;
import com.naiterui.ehp.bs.ds.modules.goods.service.IWarehouseService;
import com.naiterui.ehp.bs.ds.modules.goods.vo.WarehouseManageVO;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@Api(tags = "内部药店管理")
@RestController
@AllArgsConstructor
@RequestMapping("/inner/warehouse")
public class InnerWarehouseController {

  private final IWarehouseService warehouseService;

  @AnonymousGetMapping("/userName/{warehouseId}")
  public ResponseVO<String> getUserName(@PathVariable Long warehouseId) {
    log.info("获取药店登录名 请求参数：warehouseId = {}", warehouseId);
    String userName = this.warehouseService.getUserNameByWarehouseId(warehouseId);
    return PublicService.returnResponseVO(userName);
  }

  @AnonymousPostMapping("/manage/{warehouseId}")
  public void manage(@PathVariable Long warehouseId, @RequestBody WarehouseManageVO warehouseManage) throws BusinessException {
    log.info("更新用户信息 请求参数：warehouseId = {}, warehouseManage = {}", warehouseId, warehouseManage);
    this.warehouseService.updateManage(warehouseId, warehouseManage);
  }

  /**
   * 更新状态
   */
  @AnonymousPutMapping("/{warehouseId}/{status}")
  public void updateStatus(@PathVariable("warehouseId") Long warehouseId, @PathVariable("status") Integer status) {
    log.info("更新状态 请求参数：warehouseId = {}, status = {}", warehouseId, status);
    this.warehouseService.updateStatus(warehouseId, status);
  }

}
